package chapter1.No1_7_停止线程.b判断线程是否是停止状态;

/**
 * *：interrupted() 测试当前线程是否已经中断。这个“当前线程”就是main
 *    虽然调用的是Thread的对象：m1.interrupted()但是其实判断的是main线程是否已经中断~
 *    因为他判断的是当前线程，下面的案例实验就能说明！其实mi.interrupted()等价于
 *    Thread.interrupted();
 *
 * @author liujian
 * @version 2016/11/8 0008
 */
public class MyThreadInterrupted extends Thread {

    @Override
    public void run() {
        for(int i = 0; i < 50000; i++) {
            System.out.println(i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThreadInterrupted m1 = new MyThreadInterrupted();
        m1.start();
        Thread.sleep(100);
        m1.interrupt();
        System.out.println("是否停止1？"+m1.interrupted());
        System.out.println("是否停止2？"+m1.interrupted());
        System.out.println("是否停止3？"+Thread.interrupted());
        System.out.println("是否停止4？"+Thread.interrupted());
    }
}
